;###########################################; ; Variable width font code for Silva Saga-II; ; The change affects the main dialogue only ; ; Compiled using Byuu's xKas software. ; ; NOTE: Code inserted Assuming NO HEADER ; ;###########################################; ;########################## ; Variables that exist # ;########################## !CurrentTile = $000A ; stack relative !MemoryPointer = $14 ; stack relative !Character = $16 ; stack relative !BitsLeft = $7FFFFE ; pixels left !FontLeft = $01 ; stack relative !FontRight = $03 ; stack relative !BottomRow = $05 ; where the lower half of 8x16 goes !iLoop = $09 ; stack relative !Count = $0D ; stack relative ;########################## ; Variables that exist # ;########################## lorom ;----------------------; ; Main routine's start ; ;----------------------; main() assume mx:%00 { ;###################################################; ; ; ; ; ; Brand new font routine code ; ; ; ; ; ;###################################################; org $80FA7D _FontCodeReplacement_: ; rep #$20 lda.b !Character ; Offset to font character in ROM and.w #$00FF sta.b !Character asl asl asl asl tax ldy #$0000 ;-------------------------; ; Loop and store the data ; ;-------------------------; lda !BitsLeft ; Max pixels per tile is 8 and.w #$0007 ; Clear all garbage and use only max tile size ALWAYS! sta !BitsLeft ; replace the "pixels remaining" variable sep #$20 ;--------------- lda.b #$02 sta.b !Count ; Loop to store the top and bottom parts of the tile ;--------------- _StoreTopAndBottom_: ;-------------------------------------; ; loop and store top and bottom tiles ; ;-------------------------------------; lda.b #$08 sta.b !iLoop _FontStorageLoop_: lda.b #$00 xba lda.l _FontData_,x xba ;--------------- jsr _ShiftBits_ ; This will shift the character according ; to pixels remaining on the current tile ora (!FontRight),y sta (!FontRight),y xba ora (!FontLeft),y sta (!FontLeft),y ;--------------- iny inx ;--------------- dec.b !iLoop bne _FontStorageLoop_ ; Re-adjust the Y-index ldy.b !BottomRow ;--------------- dec.b !Count bne _StoreTopAndBottom_ ;-----------------; ; Fix pixels left ; ;-----------------; _FixPixelsLeft_: lda !BitsLeft bne _PixelsLeftOnTile_ ;--------------- lda.b #$08 ldx.b !Character sec sbc.l _Width_,x beq _UniversalEnd_ ;----------------- _MultiPurpose_: rep #$20 ldx.b !MemoryPointer dec.w !CurrentTile,x sep #$20 bra _UniversalEnd_ ;---------------------; ; ; ;---------------------; _PixelsLeftOnTile_: ; Assumes: Accum = Bits left ; ldx.b !Character sec sbc.l _Width_,x bmi _BitsOverFlowed_ beq _UniversalEnd_ bra _MultiPurpose_ ;---------------------; ; ; ;---------------------; _BitsOverFlowed_: ; Calculate what the new pixels left will ; be for the NEW tile! eor.b #$FF inc sta !BitsLeft lda.b #$08 sec sbc !BitsLeft ;---------------------; ; Go to Universal End ; ;---------------------; _UniversalEnd_: sta !BitsLeft jmp $FB2E ;############################ ; Bit Shifting Code ; ;############################ _ShiftBits_: ; Assumes X = Index to Shift Table php phx rep #$20 pha lda !BitsLeft bne _ShiftTheData_ ;------------------ pla bra _NoShift_ ;------------------ _ShiftTheData_: dec asl tax pla jmp (_Shifter_,X) _Shifter_: dw _R1,_R2,_R3,_R4,_R5,_R6,_R7 ;##########################; ; Shift bits to the right ; ;##########################; _R1: LSR _R2: LSR _R3: LSR _R4: LSR _R5: LSR _R6: LSR _R7: LSR ;------------; _NoShift_: plx plp rts } ;-------------------------------; ; Where the font data is stored ; ;-------------------------------; org $8B8000 _FontData_: ;---------------------------; ; Skip characters $00 - $1F ; ;---------------------------; padbyte $00 pad $8B8200 ;--------------------------- incbin SilvaSaga2\Src\MyFont.bin _Width_: incbin SilvaSaga2\Src\MyFont.wid }